package com.gkzf.ai.module.crm.util.assembly;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.creditreportdetails.CreditReportDetailsSaveReqVO;
import com.gkzf.ai.module.crm.dal.dataobject.creditReport.CreditReportLoanOverdueDO;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
public class OverdueInfoDetails {

    private static final String  OVERDUE_INFO_SUMMARY = "逾期明细列表";

    public static final String INSTITUTION_NAME = "机构名称";

    public static final String ACCOUNT_STATUS = "账户状态";

    public static final String OVERDUE_NUMBER = "逾期次数";

    public static final String MAX_CONTINUITIES_NUMBER = "最大连续次数";

    public static final String MAX_OVERDUE_MONTH = "最长逾期月数";

    public static final String MAX_OVERDUE_MONEY = "最高逾期金额";

    /**
     *  贷款 获取逾期明细
     * @param param
     * @param creditReportDetailsSaveReqVO
     * @return
     */
    public void getCreditReportLoanOverdue(Map<String, Object> param, CreditReportDetailsSaveReqVO creditReportDetailsSaveReqVO) {
        Object overdueDetailsList = param.get(OVERDUE_INFO_SUMMARY);
        if (overdueDetailsList instanceof JSONArray overdueDetailsArray) {
            List<CreditReportLoanOverdueDO> creditReportLoanOverdueDOList = new ArrayList<>();
            for (Object overdueDetails : overdueDetailsArray) {
                CreditReportLoanOverdueDO creditReportLoanOverdueDO = new CreditReportLoanOverdueDO();
                JSONObject overdueDetailsJson = (JSONObject) overdueDetails;
                creditReportLoanOverdueDO.setOrganizationName(AssembleUtils.getStringValue(overdueDetailsJson, INSTITUTION_NAME));

                creditReportLoanOverdueDO.setStatus(AssembleUtils.getStringValue(overdueDetailsJson, ACCOUNT_STATUS));

                creditReportLoanOverdueDO.setOverdueNumber(AssembleUtils.getStringInteger(overdueDetailsJson, OVERDUE_NUMBER));

                creditReportLoanOverdueDO.setMaxContinuousOverdueNumber(AssembleUtils.getStringInteger(overdueDetailsJson, MAX_CONTINUITIES_NUMBER));

                creditReportLoanOverdueDO.setOverdueMonth(AssembleUtils.getStringInteger(overdueDetailsJson, MAX_OVERDUE_MONTH));

                creditReportLoanOverdueDO.setOverdueMoney(AssembleUtils.getBigDecimalValue(overdueDetailsJson, MAX_OVERDUE_MONEY));
                creditReportLoanOverdueDOList.add(creditReportLoanOverdueDO);

            }
            List<CreditReportLoanOverdueDO> loanOverdueList = creditReportDetailsSaveReqVO.getLoanOverdueList();
            loanOverdueList.addAll(creditReportLoanOverdueDOList);
        }
    }
}
